#include "FWMap.h"
#include"FWTexture.h"
#include "FWGraphic.h"
#include"ShareComponent.h"
FWMap::FWMap(void)
{
}
void FWMap::LoadMatrix(string path)
{
	fstream open(path);
	open>>this->_count_Row;
	open>>this->_count_Colum;
	this->_matrix = new int*[this->_count_Row];
	for(int j=0;j<this->_count_Row;j++)
	{
		this->_matrix[j]=new int[this->_count_Colum];
	}
	for(int i=0;i<this->_count_Row;i++)
	{
		for(int j=0;j<_count_Colum;j++)
		{
			open>>this->_matrix[i][j];
		}
	}
	open.close();
}
int** FWMap::GetMatrix()
{
	return this->_matrix;
}
void FWMap::Init(string txt_matric, FWTexture* texture)
{
	this->LoadMatrix(txt_matric);
	this->_texture = texture;
}
void FWMap::Update()
{

}

void FWMap ::Render()
{
	for(int i=this->_count_Row-1;i>=0;i--)
	{
		for(int j=0;j<this->_count_Colum;j++)
		{
			RECT s_rect;
			s_rect.left= (this->_matrix[i][j]) * 32;
			s_rect.right = s_rect.left + 32;
			s_rect.top = 0;
			s_rect.bottom = 32;
			
			RECT des_rect;
			des_rect.left =j*32;
			des_rect.right=(j+1)*32;

			des_rect.top=448 - i*32;
			des_rect.bottom = des_rect.top + 32;
			glGraphic->tDrawTexture(this->_texture,s_rect,des_rect,D3DXVECTOR2(16,16),D3DCOLOR_XRGB(255,255,255),1);
		}
	}
}
FWMap::~FWMap(void)
{

}
